/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.sys.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.CacheUtils;
import com.thinkgem.jeesite.modules.sys.dao.DictDao;
import com.thinkgem.jeesite.modules.sys.entity.Dict;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;

/**
 * 字典Service
 * @author ThinkGem
 * @version 2014-05-16
 */
@Service
@Transactional(readOnly = true)
public class DictService extends CrudService<DictDao, Dict> {
	
	/**
	 * 查询字段类型列表
	 * @return
	 */
	public List<String> findTypeList(){
		return dao.findTypeList(new Dict());
	}

	@Transactional(readOnly = false)
	public void save(Dict dict) {
		super.save(dict);
		CacheUtils.remove(DictUtils.CACHE_DICT_MAP);
	}

	@Transactional(readOnly = false)
	public void delete(Dict dict) {
		super.delete(dict);
		CacheUtils.remove(DictUtils.CACHE_DICT_MAP);
	}
	@Transactional(readOnly = false)
	public Map<String,Object> leveljson() {
		Map<String,Object> result = new HashMap<String,Object>();
		try{
			Dict dict = new Dict();
			dict.setType(Global.getConfig("acq_level"));
			List<Map<String,Object>> list =  dao.leveljson(dict);
			result.put("data",list);
			result.put("success",true);
			result.put("msg","等级数据查询成功");
			return result;
		}catch(Exception e){
			e.printStackTrace();
			result.put("success",false);
			result.put("success",false);
			result.put("msg","网络异常");
			return result;
		}
		
		
	}
	
	@Transactional(readOnly = false)
	public Map<String,Object> plantAreaJson() {
		Map<String,Object> result = new HashMap<String,Object>();
		try{
			Dict dict = new Dict();
			dict.setType("plant_area_unit");
			List<Map<String,Object>> list =  dao.plantAreaJson(dict);
			result.put("data",list);
			result.put("success",true);
			result.put("msg","种植面积单位查询成功");
			return result;
		}catch(Exception e){
			e.printStackTrace();
			result.put("success",false);
			result.put("success",false);
			result.put("msg","网络异常");
			return result;
		}
		
		
	}
	
	
	@Transactional(readOnly = false)
	public Map<String,Object> returnUnitJson() {
		Map<String,Object> result = new HashMap<String,Object>();
		try{
			Dict dict = new Dict();
			dict.setType("return_unit");
			List<Map<String,Object>> list =  dao.returnUnitJson(dict);
			result.put("data",list);
			result.put("success",true);
			result.put("msg","产量单位查询成功");
			return result;
		}catch(Exception e){
			e.printStackTrace();
			result.put("success",false);
			result.put("success",false);
			result.put("msg","网络异常");
			return result;
		}
		
		
	}
	
	@Transactional(readOnly = false)
	public Map<String,Object> getData(String z,String k) {
		Map<String,Object> result = new HashMap<String,Object>();
		try{
			
			result.put("data", dao.getData(z.trim(),k.trim()));
		}catch(Exception e){
			e.printStackTrace();
		
			
		}
		return result;
		
	}
	
	@Transactional(readOnly = false)
	public Map<String,Object> trend(Integer limit,String z,String k) {
		Map<String,Object> result = new HashMap<String,Object>();
		try{
			//获取所有数据集
			List<Map<String,Object>> zMaps =z==null?null:dao.trendData(limit,z.trim());
			List<Map<String,Object>> kMaps = k==null?null:dao.trendData(limit,k.trim());
			//p率
			//d率
			//获取
			result.put("zlist", zMaps);
			result.put("klist", kMaps);
			result.put("success", true);
			result.put("msg", "接口调用成功");
			return result;
		}catch(Exception e){
			result.put("success", false);
			result.put("msg", "接口调用出错");	
			return result;
		}
		
		
	}


}
